<?php
use app\common\config\autoreply_config;
use app\common\helper\index_msg_helper;
use app\common\helper\autoreply_helper;
use app\common\helper\appmsg_helper;
?>
{include file="../app/common/admin/lib/header.html"  title="自动回复"}
{include file="../app/autoreply/view/lib/top_menu.html"}

<div class="rlbox">
  <p class="tabnav">
    <!--<a href="{/*AnUrl("autoreply/admin/add/{$autoreply_type}")}" {if $content_type == 0}class="curr"{/if} */>关联到微官网</a>-->
    <a href='{:url("/autoreply/add/$autoreply_type",["content_type"=>1])}' {if $content_type == 1}class="curr"{/if}>文字自定义回复</a>
    <a href='{:url("/autoreply/add/$autoreply_type",["content_type"=>2])}' {if $content_type == 2}class="curr"{/if}>单图文自定义回复</a>
    <a href='{:url("/autoreply/add/$autoreply_type",["content_type"=>3])}' {if $content_type == 3}class="curr"{/if}>多图文自定义回复</a>
  </p>
  {if $content_type == 0}
  <!--{$info = index_msg_helper::get_index_msg()}-->
  <!--<div class="add-form">-->
  <!--<form class="js_creatForm" action="{:url('/index_msg/admin/save')}" method="post" enctype="multipart/form-data">-->
    <!--<input type="hidden" name="from" value="{$autoreply_type}">-->
    <!--<table class="table" cellpadding="0" cellspacing="0">-->
      <!--<tr>-->
        <!--<th><label for="" class="add-f-label">官网图文标题：</label></th>-->
        <!--<td>-->
          <!--<input name="title" style="width:490px;" value="{$info.title}" type="text" class="add-f-ipt1 js_title">-->
          <!--<div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>这里是微官网首页的图文信息标题，最多输入 <span style="color:red;">64</span> 字，还可输入 <span class="js_titleNum" style="color:red;">0</span> 字</div>-->
        <!--</td>-->
      <!--</tr>-->
      <!--<tr>-->
        <!--<th valign="top"><label for="" class="add-f-label">官网图文封面：</label></th>-->
        <!--<td class="perUpOuter">-->
          <!--<div class="clearfix">-->
            <!--<div class="btn-upload left">-->
              <!--<a href="javascript:void(0);"><i class="icon-upload"></i>上传封面</a>-->
              <!--<input class="js_cover js_upFile"  type="file" name="cover">-->
            <!--</div>-->
            <!--<span class="tips left">&nbsp;&nbsp;&nbsp;<span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>推荐封面图比例：360*200</span>-->
          <!--</div>-->
          <!--<div class="js_upFileBox" {if !$info.cover}style="display:none;"{/if}>-->
              <!--{if $info.cover}<img width="238" src="{:_image($info.cover, small)}">{/if}-->
          <!--</div>-->
        <!--</td>-->
      <!--</tr>-->
      <!--<tr>-->
        <!--<th valign="top"><label for="" class="add-f-label">官网图文简介：</label></th>-->
        <!--<td>-->
          <!--<textarea class="add-f-area js_intro" name="intro">{$info.intro}</textarea>-->
          <!--<div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>内容库简介会显示在相应内容的简介位置，最多输入 <span style="color:red;">120</span> 字，还可输入 <span class="js_introNum" style="color:red;">0</span> 字</div>-->
        <!--</td>-->
      <!--</tr>-->
      <!--<tr><th>&nbsp;</th><td><button type="submit" class="btn btn-success js_submit">&nbsp;&nbsp;&nbsp;确认&nbsp;&nbsp;&nbsp;</button></td></tr>-->
    <!--</table>-->
  <!--</form>-->
<!--</div>-->
  {elseif $content_type == 1 /}
    {if $autoreply_type == 1}
      <span class="ntc">在这里设置：用户首次关注时，自动回复的信息</span>
    {else /}
      <span class="ntc">在这里设置：当用户输入的信息无法识别时，自动回复的信息</span>
    {/if}
    <div class="txtwrap">
      <div style="min-height:156px; height:auto;" contentEditable="true" class="txtfill js_replyContent">{if $content_info.content_type == 1}{$content_info.content}{/if}</div>
      <div class="txt-options clearfix">
        <a href="javascript:void(0);" class="txt-face-btn left js_faceBtn">表情</a>
        <p class="txt-count right js_fontNumBox">还可输入<span>600</span>字</p>
      </div>
    </div>
    <p class="btn-wrap"><button type="button" class="btn btn-success js_okBtn">确 认</button></p>
  {else /}
    {include file="../app/appmsg/view/lib/select_appmsg.html"}
  {/if}
</div>
<script type="text/javascript">
var autoreplyType = "{$autoreply_type}";
var contentType   = "{$content_type}";

$(function(){
  if (contentType == 0) {
    // 初始化剩余字数
    setNum('js_title', 64);
    setNum('js_intro', 120);
    $('.js_title').keyup(function(){
      setNum('js_title', 64);
    });
    $('.js_intro').keyup(function(){
      setNum('js_intro', 120);
    });
    
    // 上传图片预览
    $(".js_upFile").each(function(i){
      $(this).change(function(e){
        handleFileSelect($(this));
      });
    });
    
    // 提交验证
    $('.js_submit').click(function(e){
      e.preventDefault();
      var title      = $.trim($('.js_title').val());
      var intro      = $.trim($('.js_intro').val());
      if (!title) {
        showMsg('标题不能为空');
        return;
      }
      if (getFontNum(title) > 64) {
        showMsg('标题不能超过64字');
        return;
      }
      if (!intro) {
        showMsg('简介不能为空');
        return;
      }
      if (getFontNum(intro) > 120) {
        showMsg('简介不能超过120个字');
        return;
      }
      
      $('.js_creatForm').submit();
    });
    
  } else if (contentType == 1) {
    // 初始字数
    syncNum($(".js_replyContent"), $(".js_fontNumBox"), 600);
    
    $(".js_replyContent").focus();
    // 字数
    $(".js_replyContent").keyup(function(){
     syncNum($(this), $(".js_fontNumBox"), 600);
    });
    
    // 表情
    weiboFace($(".js_faceBtn"), $('.js_replyContent'));
  }
  
  // 提交
  $(".js_okBtn").click(function(){
    var replyContent = $(".js_replyContent").html();
    /*if (!replyContent || !$.trim(replyContent)) {
      showMsg('回复的内容不能为空');
      return;
    }*/
    if (replaceBlank(replyContent) == "0") {
      showMsg('请输入有意义的回复内容');
      return;
    }
    syncNum($(".js_replyContent"), $(".js_fontNumBox"), 600);
    var _num = getNum($(".js_replyContent"));
    if (_num < 1) {
      showMsg('回复的内容不能为空.');
      return;
    }
    if (_num > 600) {
      showMsg('回复的内容不能不能超过600字');
      return;
    }
    
    var postData = { 'content':replyContent, 'autoreply_type':autoreplyType, 'content_type':contentType };
    $.post(siteUrl+'/autoreply/save/'+autoreplyType, postData, function(json){
      if (json.info != 'ok') {
        showMsg(json.info);
        return;
      }
      
      showMsg('更改成功', 1);
      window.location.href = siteUrl+'/autoreply/admin/'+autoreplyType;
        //console.log( siteUrl+'/autoreply/admin/'+autoreplyType);
    }, 'json');
  });
  
  // 选择某一条图文做为回复
  $(".js_msgList>li").live('click', function(e){
    e.preventDefault();
    var thisObj = $(this);
    if (!thisObj.hasClass('curr')) {
      var id = thisObj.attr('data-id');
      if (!id) {
        showMsg('请选择一条信息');
        return false;
      }
      
      showConfirm('您确定要选择该图文信息吗?', 1, function(){
        $.post(siteUrl+'/autoreply/save/'+autoreplyType, { 'autoreply_type':autoreplyType, 'content_type':contentType, 'content':id }, function(json){
          if (json.info != 'ok') {
            showMsg(json.info);
            return false;
          }
          
          $(".js_msgList li.curr").removeClass('curr');
          thisObj.addClass('curr');
          
          showMsg('选择成功', 1);
          window.location.href = siteUrl+'/autoreply/admin/'+autoreplyType;
        }, 'json');
      });
    }
  });
});
function setNum(thisClass, maxNum) {
  var presentNum = getFontNum($('.'+thisClass).val());
  var remainNum  = maxNum - presentNum;
  $('.'+thisClass+'Num').text(remainNum);
}
</script>
{include file="../app/common/admin/lib/footer.html"}